package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.query.ProductQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IProductService;
import cn.wolfcode.trip.base.service.IProductTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//商品资源控制器
@RestController
@RequestMapping("/products")
public class ProductController {
    @Autowired
    private IProductTypeService productTypeService;
    @Autowired
    private IProductService productService;
    /**
     * 查所有的商品分类
     * 资源:/products/productTypes
     * 动作:Get
     */
    @GetMapping("/productTypes")
    public Object getProductType(QueryObject qo){
        return productTypeService.queryProductType(qo);

    }

    /**
     * 查某个分类所有的商品
     * 资源:/products
     * 动作:Get
     * 参数:productTypeId
     */
    @GetMapping("/qo")
    public Object getProductByType(ProductQueryObject qo){
        return productService.queryProduct(qo);

    }
    /**
     * 根据id查商品信息
     * 资源:/products
     * 动作:Get
     * 参数:id
     */
    @GetMapping("/{id}")
    public Object getProductById(@PathVariable Long id){
        return productService.getProductById(id);

    }

    /**
     * 查最近添加的商品
     * 资源:/products
     * 动作:Get
     */
    @GetMapping()
    public Object getNewProduct(){
        return productService.getNewProduct();

    }


}
